
/*
 * File:   pq.c
 * Author: aishwarya
 *
 * Created on March 12, 2011, 4:02 AM
 * Priority Queue - Implementation
 */
#include "pq.h"

/*
Initializes a PRIORITY QUEUE
 */
void pq_init(PQ *q, size_t initial_size, size_t e_size,
        KEYCMP k, DATACPY d, DELNODE n, PRINTNODE p) {
    q->THIS = q;
    heap_init(&(q->heap), initial_size, e_size, k, d, n, p);
}

int is_pq_empty(PQ *q) {
    return (q->heap.heap_size == 0) ? 1 : 0;
}

void pq_enqueue(PQ *q, const void *n, int id) {
    min_heap_insert(&(q->heap), id, n);
}

void pq_dequeue(PQ *q, void *min) {
    heap_extract_min(&(q->heap), min);
}

void pq_peek(PQ *q, void *min) {
    heap_minimum(&(q->heap), min);
}

void pq_delete(PQ *q) {
    heap_clean(&(q->heap));
}

void pq_decrease_priority(PQ *q, void *n, int id) {
    heap_decrease_key(&(q->heap), id, n);
}


